package com.cipta.lomob.fragments;

import java.util.LinkedList;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

import com.cipta.lomob.R;
import com.cipta.lomob.adapter.ItemProfileAdapter;
import com.cipta.lomob.base.BaseFragment;
import com.cipta.lomob.model.ItemProfile;
import com.cipta.lomob.model.Users;
import com.cipta.lomob.utils.SampleData;

public class UserProfileFragment extends BaseFragment{
	private ListView lvItem;
	private LinkedList<ItemProfile> listItem;
	private Users user;
	//
	private ImageView userAvatar;
	
	public static String FRAGMENT_TAG = "UserProfileFragment";
	
	public UserProfileFragment(){
		
	}
	
	public UserProfileFragment(Users iUser){
		this.user = iUser;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		initializeLibs();
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.fragment_profile, container, false);
		setHasOptionsMenu(true);
		getActivity().getActionBar().setTitle("Yoze Hariando");
		initializeViews(view);
		return view;
	}
	
	@Override
	public void initializeLibs() {
		// TODO Auto-generated method stub
		super.initializeLibs();
		listItem = new LinkedList<ItemProfile>();
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		
		initializeProcess();
		initializeActions();
	}
	
	@Override
	public void initializeViews(View view) {
		super.initializeViews(view);
		lvItem = (ListView)view.findViewById(R.id.lv_profile);
		View header = getActivity().getLayoutInflater().inflate(R.layout.header_view_profile, null);
		lvItem.addHeaderView(header);
	}
	
	@Override
	public void initializeProcess() {
		super.initializeProcess();
		
		
		
		ItemProfile itemProfile = null;
		for (int i = 0; i < SampleData.sampleDataItemProfile.length; i++) {
			itemProfile = new ItemProfile();
			itemProfile.setTitle(SampleData.sampleDataItemProfile[i][0]);
			itemProfile.setComments(SampleData.sampleDataItemProfile[i][1]);
			itemProfile.setLikes(SampleData.sampleDataItemProfile[i][2]);
			itemProfile.setWatching(SampleData.sampleDataItemProfile[i][3]);
			itemProfile.setIsLive(SampleData.sampleDataItemProfile[i][4]);
			itemProfile.setThumbnail(SampleData.sampleImageItemProfile[i]);
			
			listItem.add(itemProfile);
		}
		
		ItemProfileAdapter itemProfileAdapter = new ItemProfileAdapter(getActivity(), listItem);
		lvItem.setAdapter(itemProfileAdapter);
	}
	
	@Override
	public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
		super.onCreateOptionsMenu(menu, inflater);
		inflater.inflate(R.menu.menu_profile, menu);
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if (item.getItemId()==R.id.action_followers) {
			Toast.makeText(getActivity(), "To friends", Toast.LENGTH_LONG).show();
		}
		return super.onOptionsItemSelected(item);
	}
}
